package Offer052

class Main {

}

/**
 * kotlin 展平二叉搜索树
 */
fun main() {

}

class TreeNode2() {
    //kotlin次构造函数
    var left: TreeNode2? = null
    var right: TreeNode2? = null
}

class Solution2 {
    var pre = TreeNode2()
    var node = pre
    fun increasingBST(root: TreeNode2?): TreeNode2? {
        return helper(root)
    }

    private fun helper(root: TreeNode2?): TreeNode2? {
        if(root == null){
            return null
        }
        helper(root.left)
        node.right = TreeNode2()
        node = node.right!!
        helper(root.right)
        return pre.right
    }
}